package com.patchmanage.back.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.patchmanage.back.dto.InventoryPatchDto;
import com.patchmanage.back.entity.InventoryPatch;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huizhao
 * @since 2021-07-11
 */
public interface InventoryPatchMapper extends BaseMapper<InventoryPatch> {

    @Select({"<script>",
            "select i.*,p.cve_cvss3_severity,cve_cvss3_score from inventory_patch i " +
                    "left join patch p on(i.cve_id = p.cve_id) ",
            "WHERE 1=1 ",
            "AND i.query_id = #{map.query_id}",
            "<if test='map.host != null and map.host != &quot;&quot;'>",
            "AND (i.host like CONCAT('%',#{map.host},'%'))",
            "</if>",
            "<if test='map.search != null and map.search != &quot;&quot;'>",
            "AND (i.affect_packages like CONCAT('%',#{map.search},'%'))",
            "</if>",
            "</script>"})
    IPage<InventoryPatchDto> selectInventoryPatchExPage(IPage<InventoryPatchDto> page, @Param("map") Map dict);

}
